#pragma once

#include <pthread.h>

//对加锁和解锁进行封装,对象创建时加锁,销毁时释放锁
class LockGuard
{
public:
    LockGuard(pthread_mutex_t lock) : _lock(lock)
    {
        pthread_mutex_lock(&_lock);
    }

    ~LockGuard()
    {
        pthread_mutex_unlock(&_lock);
    }

private:
    pthread_mutex_t _lock;
};